<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>项目提前结清详情</title>
<jsp:include page="../../import.jsp" flush="true" />
<style type="text/css">
</style>
</head>
<body class="iframeBody">
<div class="Wrapper">
     <div class="fieldset1 tabel_col tabel_col_s clearFix">
         <div class="caption">
			<span class="title">项目提前结清信息 </span>
		</div>
		<div class="fieldBox col_33">
		   <div class="label">项目名称</div>
		   <div class="field">
              <span id="fncPrjNm" ></span>
           </div>
		</div>
		<div class="fieldBox col_33">
		   <div class="label">项目编号</div>
		   <div class="field">
              <span id="fncPrjIdStr" ></span>
           </div>
		</div>
		<div class="fieldBox col_33">
		   <div class="label">创建时间</div>
		   <div class="field">
              <span id="prjCrtTm" ></span>
           </div>
		</div>
		<div class="fieldBox col_33">
		   <div class="label">融资机构</div>
		   <div class="field">
              <span id="fncInsNm" ></span>
           </div>
		</div>
		<div class="fieldBox col_33">
		   <div class="label">融资方案</div>
		   <div class="field">
              <span id="fncScmNm" ></span>
           </div>
		</div>
		<div class="fieldBox col_33">
		   <div class="label"></div>
		   <div class="field">
		       <span></span>
           </div>
		</div>
		<div class="fieldBox col_33">
		   <div class="label">提前结清期次</div>
		   <div class="field">
             <span id="esPd"></span> 
           </div>
		</div>
		<div class="fieldBox col_33">
		   <div class="label">预计结清时间</div>
		   <div class="field">
		     <span id="payTm"></span>
           </div>
		</div>
		<div class="fieldBox col_33">
		   <div class="label"></div>
		   <div class="field">
		     <span></span>
           </div>
		</div>
		<div class="fieldBox col_33">
		   <div class="label">机构收款单位</div>
		   <div class="field">
              <span id="reAccNm" ></span>
           </div>
		</div>
		<div class="fieldBox col_33">
		   <div class="label">机构收款开户行行名</div>
		   <div class="field">
             <span id="reBanAccNm"></span>
           </div>
		</div>
		<div class="fieldBox col_33">
		   <div class="label">机构收款账号</div>
		   <div class="field">
              <span id="reAccNum" ></span>
           </div>
		</div>
		<div class="fieldBox col_33">
		   <div class="label">我司付款单位</div>
		   <div class="field">
             <span id="payBanAccNm"></span>
           </div>
		</div>
		<div class="fieldBox col_33">
		   <div class="label">我司付款开户行行名</div>
		   <div class="field">
              <span id="payAccNm" ></span>
           </div>
		</div>
		<div class="fieldBox col_33">
		   <div class="label">我司付款账号</div>
		   <div class="field">
             <span id="payAccNum"></span>
           </div>
		</div>
		<div class="fieldBox col_33">
		   <div class="label">应还本金</div>
		   <div class="field">
		     <span id="capital"></span>
           </div>
		</div>
		<div class="fieldBox col_33">
		   <div class="label">应还利息</div>
		   <div class="field">
		     <span id="interest"></span>
           </div>
		</div>
		<div class="fieldBox col_33">
		   <div class="label">其他费用</div>
		   <div class="field">
		     <span id="otherChar"></span>
           </div>
		</div>
		<div class="fieldBox col_33">
		   <div class="label">结清费用</div>
		   <div class="field">
		     <span id="setlleChar"></span>
           </div>
		</div>
		<div class="fieldBox col_33">
		   <div class="label">合计</div>
		   <div class="field">
		     <span id="allChar"></span>
           </div>
		</div>
		<div class="fieldBox col_33">
		   <div class="label"></div>
		   <div class="field">
           </div>
		</div>
		<div class="fieldBox col_100" id="fileModify">
			<div class="label">资料</div>
			<div class="field">
               	<jsp:include page="../../system/sysUlFilesRec/sysUlFileRecList.jsp" flush="true" >
                  	<jsp:param name="pkId" value="${lgcId }"/>
                  	<jsp:param name="tabNm" value="CST_BSC_INFO"/>
                </jsp:include>
           	</div>
		</div> 
	    <div class="fieldBox col_100" id="fileModify">
			<div class="label">备注</div>
			<div class="field" style="width:100%" >
			     <textarea name="rmrk" id="rmrk" rows="4" class="l-textarea" style="width:100%"></textarea>
		    </div>
		</div> 
	</div><br/>
	<div class="fieldset1 tabel_col_s clearFix" > <!-- fieldset1 tabel_col tabel_col_s clearFix -->
	   <div class="caption">
		   <span class="title" >还款列表 </span>
	   </div>
	  <div id="prjPayTbligergrid" class="sq-grid"></div>
	</div>
	<!-- hidden -->
	<input name="lgcId" id="lgcId" type="hidden" class="ui-textbox" value="${lgcId}"  >
	<input name="prjid" id="prjid" type="hidden" class="ui-textbox" value="${prjLgcId}"  >
</div>

<script type="text/javascript">
   $(function() {
	  initData();
	 });
   
   function initData(){
	  var lgcId=$("#lgcId").val();
	  var prjLgcId=$("#prjid").val();
	  if(!prjLgcId&&!lgcId)  return;
	  var data=new Object();
	  data["lgcId"]=lgcId;
	  data["prjLgcId"]=prjLgcId;
	  var _url = '<%=path%>/rfbase/fncprjeaplysettle/prjEaplySettleUpdatePageinit.do';
	   AjaxUtils.ajaxPost(_url, data, callback);
	}
		
	  //新增回调
   function callback(msg){
	  if(msg.success == 1){
		  setData(msg.data);//设置数据
	  }else{
		  UIUtils.alertError(msg.info);
	  }
   }
		 
	//设置页面数据
   function setData(data){
	    var settlePrjDetail=data["settlePrjDetail"];
	    var prjPayInfoList=data["FncPrjPayTbInfoList"];
	    var fncPrjEaplySettle=settlePrjDetail.fncPrjEaplySettle;
	    $("#fncPrjIdStr").html(settlePrjDetail.fncPrjIdStr);
	    $("#fncPrjNm").html(settlePrjDetail.fncPrjNm);   
	    $("#prjCrtTm").html(renderDateChange(settlePrjDetail.crtTm)); 
		$("#fncInsNm").html(settlePrjDetail.fncInsNm);
		$("#fncScmNm").html(settlePrjDetail.fncScmNm);
		$("#esPd").html(fncPrjEaplySettle.esPd);
		$("#payTm").html(renderDateChange(fncPrjEaplySettle.payTm));
	    $("#reBanAccNm").html(fncPrjEaplySettle.reBanAccNm);
		$("#reAccNm").html(fncPrjEaplySettle.reAccNm);
		$("#reAccNum").html(fncPrjEaplySettle.reAccNum);
		$("#payBanAccNm").html(fncPrjEaplySettle.payBanAccNm);
		$("#payAccNm").html(fncPrjEaplySettle.payAccNm);
		$("#payAccNum").html(fncPrjEaplySettle.payAccNum);
		$("#capital").html(moneyChange(fncPrjEaplySettle.capital));
		$("#interest").html(moneyChange(fncPrjEaplySettle.interest));
		$("#setlleChar").html(moneyChange(fncPrjEaplySettle.setlleChar));
		$("#otherChar").html(moneyChange(fncPrjEaplySettle.otherChar));
		$("#allChar").html(moneyChange(fncPrjEaplySettle.allChar));
		$("#rmrk").val(fncPrjEaplySettle.rmrk);
		//计算还款表
		 var esPd=fncPrjEaplySettle.esPd;
		 var interestVale=fncPrjEaplySettle.interest;
		 for(var i=esPd-1;i<prjPayInfoList.length;i++){
		    if(i==esPd-1)
	        {
			   prjPayInfoList[i].interestEp=fncPrjEaplySettle.esPdInterest;
			}
		    else{
			   prjPayInfoList[i].interestEp=0;
			}
		}
		//编辑剩余本金
		prjPayInfoList[prjPayInfoList.length-1].srplsCapitalEp=0;
		for(var i=0;i<prjPayInfoList.length-1;i++){
			prjPayInfoList[prjPayInfoList.length-2-i].srplsCapitalEp=prjPayInfoList[prjPayInfoList.length-1-i].srplsCapitalEp+prjPayInfoList[prjPayInfoList.length-1-i].arCapital;
		}
		f_showprjPayTbInfo(prjPayInfoList);
  };

  function f_getDetailData(listChange)
  {
      var data = { Rows: [] };
      for (var i = 0; i < listChange.length; i++)
      {
         data.Rows.push(listChange[i]);
      }
      return data;
  }
 
   //显示还款List
    function f_showprjPayTbInfo(prjPayInfoList)
    { 
	    $("#prjPayTbligergrid").ligerGrid({
	        columns: [
	            { display: '支付表详细逻辑编号',name: "id", width: 150,hide: true}, 
	            { display: '期次', name: 'payPdEp', width: 150 },
	            { display: '支付时间', name: 'payTmEp', width: 150, render:renderDate},
	            { display: '租金', name: 'rentalEp', width: 100, render: function (rowdata, rowindex, value, column) { 
	            	var money =moneyChange(value);
                    return money;
            		},
        	enabledSort:true}, 
	            { display: '本金', name: 'capitalEp', width: 100, render: function (rowdata, rowindex, value, column) { 
	            	var money =moneyChange(value);
                    return money;
            		},
        	enabledSort:true}, 
	            { display: '利息', name: 'interestEp', width: 100, render: function (rowdata, rowindex, value, column) { 
            		var money =moneyChange(value);
                    return money;
            		},
        	
        	enabledSort:true}, 
	            { display: '已还租金', name: 'rentaledEp', width: 200, render: function (rowdata, rowindex, value, column) { 
            		var money =moneyChange(value);
                    return money;
            		},
        	enabledSort:true}, 
	            { display: '剩余本金', name: 'srplsCapitalEp', width: 100, render: function (rowdata, rowindex, value, column) { 
	            	var money =moneyChange(value);
                    return money;
            		},
        	enabledSort:true}
	        ],
	        usePager:false,
	        data:f_getDetailData(prjPayInfoList),
	        width:'100%',
	        height:'400'
	    });
    }
	
 //格式化时间
 function renderDateChange(value){
	var dateStr = "";
	if(null != value &&  ""!= value){
		var date = new Date(value);
		dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
	}
	return dateStr;
 } 
 
//格式化时间
 function renderDate(rowdata, index, value){
	var dateStr = "";
	if(null != value){
		var date = new Date(value);
		dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
	}
	return dateStr;
 }
 
 function moneyChange(value) { 
		var h = '';
			if(value&&value!="null"){
		    h+=fmoney(value, 2);
			}else{
			h+="0.00";
			}
         return h;
		}
 
 //格式化金额
 function fmoney(s, n)   
	{   
	   n = n > 0 && n <= 20 ? n : 2;   
	   s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";   
	   var l = s.split(".")[0].split("").reverse(),   
	   r = s.split(".")[1];   
	   t = "";   
	   for(i = 0; i < l.length; i ++ )   
	   {   
	      t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");   
	   }   
	   return t.split("").reverse().join("") + "." + r;   
	} 
 
</script>

</body>
</html>
